package com.fulihui.wgj.admin.api.platform;

import com.fulihui.common.builder.web.JsonResultBuilder;
import com.fulihui.common.result.web.PageView;
import com.fulihui.common.result.web.Result;
import com.fulihui.wgj.admin.api.base.BaseController;
import com.fulihui.wgj.admin.api.platform.request.WxPlatformPageReq;
import com.fulihui.wgj.admin.api.platform.vo.WxPlatformVO;
import com.fulihui.wgj.admin.integration.WxPlatformClient;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.Objects;

/**
 * @author: JY
 * @date: 2018/7/2 18:04
 * 公众号操作
 */
@RestController
@RequestMapping("/platform")
@Api(tags = "公众号相关接口")
public class PlatformController extends BaseController {

    @Autowired
    WxPlatformClient wxPlatformServiceClient;

    /**
     * 获取公众号列表
     */
    @PostMapping("/list")
    @ApiOperation("获取公众号列表")
    public Result<PageView<WxPlatformVO>> platformList(@RequestBody @Valid WxPlatformPageReq request, BindingResult validResult) {
        Result valid = valid(validResult);
        if (Objects.nonNull(valid)) {
            return valid;
        }
        request.setLoginId(getLoginId());
        PageView<WxPlatformVO> pageView = wxPlatformServiceClient.queryWxPlatformPage(request);
        return JsonResultBuilder.succ(pageView);
    }
}
